package com.gzq.administrator.testthread;


import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment extends Fragment {


    private View view;
    private HandlerHelper<BlankFragment> handlerHelper;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_blank, container, false);
        handlerHelper = new HandlerHelper<>(this);
        Message message = new Message();
        message.obj = "你好你好";
        handlerHelper.sendMessage(message);

        handlerHelper.setOnHandlerResult(new HandlerHelper.HandlerResult<BlankFragment>() {
            @Override
            public void handleMessage(Message msg, BlankFragment self) {
                Toast.makeText(getContext(), (CharSequence) msg.obj, Toast.LENGTH_SHORT).show();
            }
        });
        view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().getSupportFragmentManager().beginTransaction().remove(BlankFragment.this).commit();
            }
        });
        return view;
    }

}
